﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using SQL = KC.DataAccess.Global.SQL;

namespace KC.Business
{
	public static class MVCMS
	{
		/// <summary>Copies a DataGridView</summary>
		/// <param name="dgFrom">Copy from this grid</param>
		/// <param name="dgTo">Copy to this grid</param>
		public static void CopyDatagridview(DataGridView dgFrom, ref DataGridView dgTo)
		{
			dgTo.Font = new Font(dgTo.Font.FontFamily, 8);

			foreach (DataGridViewColumn col in dgFrom.Columns)
				dgTo.Columns.Add(col.Name, col.Name);

			foreach (DataGridViewRow row in dgFrom.Rows) {
				dgTo.Rows.Add(row.Clone());
				for (int i = 0; i < row.Cells.Count; i++)
					dgTo.Rows[dgTo.Rows.Count - 1].Cells[i].Value = row.Cells[i].Value;
			}


			

			for (int x = 0; x < dgFrom.Columns.Count; x++) {  // Copy column formats
				dgTo.Columns[x].DefaultCellStyle = dgFrom.Columns[x].DefaultCellStyle;
				dgTo.Columns[x].AutoSizeMode = dgFrom.Columns[x].AutoSizeMode;
				dgTo.Columns[x].Width = dgFrom.Columns[x].Width; }

			for (int x = 0; x < dgTo.Rows.Count; x++) {  // Copy row formats
				dgTo.Rows[x].DefaultCellStyle = dgFrom.Rows[x].DefaultCellStyle;
				dgTo.Rows[x].Height = 30;
				for (int y = 0; y < dgFrom.Columns.Count; y++) { // Copy cell formats
					dgTo.Rows[x].Cells[y].Style = dgFrom.Rows[x].Cells[y].Style;
					dgTo.Rows[x].Cells[y].Value = dgFrom.Rows[x].Cells[y].Value;
					dgTo.Rows[x].Cells[y].Tag = dgFrom.Rows[x].Cells[y].Tag; }
				dgTo.Rows[x].Cells[0].Style.Font = new Font(dgTo.Font.FontFamily, 8); }
		}
	}
}
